//
//  Parser.h
//  LightBasic
//
//  Created by Albert on 21/03/2011.
//  Copyright 2011 LightBasic Development Team. All rights reserved.
//
#pragma once
#include "TokenType.h"
#include "Ast.h"

namespace lbc {
    
    /// Class references
    class Context;
    class Token;
    class Lexer;
    
    /**
     * The parser
     */
    class Parser : boost::noncopyable
    {
        public:
        
        /// Create new parser instance
        Parser(Context & context);
        
        /// Parse
        AstProgram * Parse();
        
        private:
        
        /// match current token
        bool Match(TokenType type) const;
        
        /// Accept token and move to the next
        bool Accept(TokenType type);
        
        /// expect a token. Throw an error if doesn't match
        void Expect(TokenType type);
        
        /// Move to the next one
        void Move();
        
        /// compilation context
        Context & m_context;
        /// current token
        Token * m_token;
        /// Next token
        Token * m_nextToken;
        /// Lexer object
        Lexer * m_lexer;
    };
    
}